package com.jf.blogbackened.service.impl;

import com.jf.blogbackened.bean.Result;
import com.jf.blogbackened.bean.Statistics;
import com.jf.blogbackened.bean.vo.ArticleVO;
import com.jf.blogbackened.mapper.ArticleMapper;
import com.jf.blogbackened.mapper.StatisticsMapper;
import com.jf.blogbackened.service.IndexService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author David
 */
@Service
public class IndexServiceImpl implements IndexService {
    @Resource
    private StatisticsMapper statisticsMapper;
    @Resource
    private ArticleMapper articleMapper;

    @Override
    public Result getStatistics() {
        Statistics statistics = new Statistics();
        // 查询统计数据
        Long userCount = statisticsMapper.getUserCount();
        Long articleCount = statisticsMapper.getArticleCount();
        Long commentCount = statisticsMapper.getCommentCount();
        Long hitsCount = statisticsMapper.getHitsCount();
        // 查询最近文章列表
        List<ArticleVO> recentArticles = articleMapper.getRecentArticles();
        statistics.setArticles(recentArticles);
        statistics.setUserCount(userCount);
        statistics.setArticleCount(articleCount);
        statistics.setCommentCount(commentCount);
        statistics.setHits(hitsCount);
        // 封装结果
        return Result.ok().data(statistics);


    }
}
